#ifndef DATEBASE_H
#define DATEBASE_H
#include <QtSql>
#include <QString>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <QDebug>
#include <QLatin1String>
#include <QMessageBox>
#include <QVariant>
#include <QXmlStreamAttributes>
#include <QTextCodec>
#include <QtScript>
#include "cJSON.h"
typedef struct
{
  QString ticketReturn;     //返回
  QString parkTime;
  QString beginTime; //停车开始
  QString endTime;
  QString dirflag; //？？？？？
  QString car_no;
  QString car_id;
  QString update_time;
  QString ic_sn;
  double money;
  QString pass_num;
  int dayAuto;
  QString houseNo;
  QString image_name;
  QString parked_time;
  QString fee_type;
  QString car_type;
  QString person_name;
  QString person_tel;
  QString person_address;//车位
  QByteArray flag;
  QString status;
  QString inImage;
  QString outImage;
  QString receivable;
  QString actual_money;
  QString discount;
  QString user;
}ticketCheck_t;

typedef struct
{
   QString carReturn; QString parkTime;
   QString car_no;QString status;
   QString car_type;QString start_date;
   QString stop_date;QString vehicle_type;
   int dayAuto;
}car_Check;
typedef struct
{
    QString id_car;
    QString car_no;
    QString car_type;
    QString person_name;
    QString person_tel;
    QString person_address;
    QString start_date;
    QString stop_date;
    QString status;
    QString fee_type;
    QString begin_time;
    QString end_time;
    QString allow_count;
    QString allow_park_time;
    QString vehicle_type;
    QString created_at;
    QString updated_at;
}webcar_down;

typedef struct
{
    QString pass_no;     //返回
       QString car_type;
       QString car_no; //停车开始
       QString in_time;
       QString in_operator;
       QString in_image;
       QString stall_code;
       QString out_time;
       QString out_operator;
       QString out_image;
       QString status;
       QString fee;
       QString fact_fee;
       QString created_at;
       QString vehicle_type;
       QString updated_at;
       QString parked_time;
       QString updated_controller_sn;
       float promote_fee;
       float single_fee;
       int paytype;
       int flag;
}web_record_in_out;

typedef struct
{
    QString code;
    QString car_no;
    QString stall_code;
    QString status;
    QString begin_date;
    QString end_date;
    QString created_at;
    QString updated_at;
}web_car_bind;

typedef struct
{
    QString area_code;
    QString print_code;
    QString stall_code;
    QString status;
    QString created_at;
    QString updated_at;
}web_car_stall;


//zhangjie序号：车牌号：类型： 车位：联系人：电话：开始时间：结束时间
typedef struct
{
    QString car_no;
    QString car_type;
    QString code_Id;
    QString person_name;
    QString person_tel;
    QString start_date;
    QString stop_date;
}car_stall_info;
typedef struct
{
    QString car_no;
    QString car_type;
    QString in_time;
    QString out_time;
    int modife_flag;
    int stall_time;
    float receivable;
    float actual_money;
    float discount;
    int pay_way; //1现金支付
}car_record_info;
//zhangjie end

typedef struct
{
    QString id;
    QString login;
    QString password;
    QString user_type;
    QString status;
    QString created_at;
    QString updated_at;
 }user_info;
//杰哥
typedef struct
{
  QString car_no;
  QString in_time;
  QString in_image;
}car_in_find;
class datebase
{
public:
    datebase();
    void databse_close();
    int CarSeatSearch(QSqlDatabase *db,QString per_num);
    bool CarSeatIn(QSqlDatabase *db,QString per_num,int carNum,QString);
    bool car_chek(QSqlDatabase *db,ticketCheck_t *checkInfo,QString,QString car_no);
    bool car_outchek(QSqlDatabase *db,ticketCheck_t *checkInfo,QString vehicle_flag,QString vehicle_no);
    bool car_chek(QSqlDatabase *db,car_Check *carInfo,QString vehicle_flag,QString vehicle_no);
    bool writeCarLinInLog(QSqlDatabase *db,QString,QString pic_name,QString,QString,QString statu);
    bool writeCarInLog(QSqlDatabase *db,QString car_no,QString picname,QString car_type,QString stall_code,QString statu,QString in_user);
    QString check_stall_car(QSqlDatabase *db,QString carNum,QStringList stall_code);
    bool writeCarOutLog(QSqlDatabase *db,QString pic_outname,QString fee,ticketCheck_t *checkInfo);
    bool updateCarOutLog(QSqlDatabase *db,QString vehicle_no);
    bool updateCarOutLog(QSqlDatabase *db,QString carNum,QString cartype,QString stall_code);
    bool CarOutInfo(QSqlDatabase *db,  QString vehicle_no,ticketCheck_t *checkInfo);
    bool CarOutInfo(QSqlDatabase *db, QString vehicle_flag, QString vehicle_no,ticketCheck_t *checkInfo);
    bool writeSqliteCar(QSqlDatabase *db, ticketCheck_t *checkInfo);
    bool writeSqliteCarweb(QSqlDatabase *db,webcar_down *webCarInfo);
    void hand_delete(QSqlDatabase *db);
    void car_delete(QSqlDatabase *db,QString car_no);
    void cardate_delete(QSqlDatabase *db);
    void inOut_delete(QSqlDatabase *db,QString car_no);
    void inOutIc_delete(QSqlDatabase *db,QString card_no);
    void inOutDay_delete(QSqlDatabase *db);
    void hand_insert(QSqlDatabase *db,QString,QString);
    web_record_in_out select_inout_record(QSqlDatabase *db,web_record_in_out);
    bool update_record_flag(QSqlDatabase *db,web_record_in_out info_record);

    QString select_updateTime_record(QSqlDatabase *db);
    bool update_lasttime_record(QSqlDatabase *db,QString lasttime);
    QString select_updateTime_carbind(QSqlDatabase *db);

    int send_in_out_record(QSqlDatabase *db,ticketCheck_t *checkInfo);
    QString select_carTime(QSqlDatabase *db);
    QString get_park_time(int sec);  //计算停车时长
    int get_park_minute(QString begin_time,QString end_time);
    double get_park_money(QSqlDatabase *db,QString,QString,QString);  //计算停车费用
    bool inOutimage_selcet(QSqlDatabase *db,ticketCheck_t *checkInfo);
    bool inOutimage_insert(QSqlDatabase *db,QString pic_name,QString car_no,QString);
    bool inOutimage_move(QSqlDatabase *db,QString pic_name);
    bool inOutDir_move(QSqlDatabase *db,QString dirname);
    QString userNameCheck(QSqlDatabase *db);
    QString hand_InImage(QSqlDatabase *db,QString picname);
    bool userNameUpdate(QSqlDatabase *db,QString passwd);

    bool SqliteDbCheck(QSqlDatabase *db,ticketCheck_t *checkInfo);
    QSqlDatabase sqlite_db;
    QSqlDatabase sqlite_db_bei;
    QString select_updateTime(QSqlDatabase *db);
    QString select_updateTime_carstall(QSqlDatabase *db);
    bool insert_record_in_out(QSqlDatabase *db,web_record_in_out *recordInfo);
    bool update_record_in_out(QSqlDatabase *db,web_record_in_out *recordInfo);
    QString check_pass_no(QSqlDatabase *db,web_record_in_out *recordInfo);
    bool insert_car_stall(QSqlDatabase *db,web_car_stall *webCarstall);
    bool check_car_stall(QSqlDatabase *db,web_car_stall *webCarstall);
    bool delete_car_stall(QSqlDatabase *db,web_car_stall *webCarstall);
    bool insert_car_bind(QSqlDatabase *db,web_car_bind *webCarbind);
    bool check_car_bind(QSqlDatabase *db,web_car_bind *webCarbind);
    bool delete_car_bind(QSqlDatabase *db,QString car_no,QString stall_code);
    bool delete_car_bind(QSqlDatabase *db,QString car_no);
    bool check_car_bind(QSqlDatabase *db,QString carNum);
    bool update_car_bind(QSqlDatabase *db,web_car_bind *webCarbind);
    QStringList select_stall_code(QSqlDatabase *db,QString carNum);
    /******张超****start***/
    bool setFeeData(QSqlDatabase *db,QString codename,float banFee,float yiFee);
    bool setUserData(QSqlDatabase *db,QString name,QString pass,QString type);
    bool updateFeeData(QSqlDatabase *db,QString id,QString codename,QString fee);
    QString selectUserData(QSqlDatabase *db,QString name);
    bool insertUserData(QSqlDatabase *db,user_info *info);
    bool updateUserData(QSqlDatabase *db,int flag,QString userName,QString pass,QString type);
    bool deleteUserData(QSqlDatabase *db,QString userName);
    QString FindSeatData(QSqlDatabase *db,QString car_no);
    void DeleteStall_vehicle(QSqlDatabase *db);
    /******张超****end***/
    /******张杰****start****/
    QList<car_record_info> select_record_info(QSqlDatabase *db, QString car_no, QString car_type, QString min_time, QString max_time);
    QList<car_stall_info> select_vehicle_info(QSqlDatabase *db,QString carNum);
    QList<car_record_info> select_Fee_info(QSqlDatabase *db,QString car_no,QString Operator,QString min_time,QString max_time);
    car_record_info select_detail_record_Fee_info(QSqlDatabase *db,QString car_no,QString car_type,QString intime,QString outtime);
    QStringList select_user(QSqlDatabase *db);
    QStringList select_detail_record_info(QSqlDatabase *db,QString car_no,QString car_type,QString intime,QString outtime);
    /******张杰****end****/
    void deleteSeat(QSqlDatabase *db);
    QList<car_in_find> select_in_car(QSqlDatabase *db, int flag, QString car_no, QString car_type, int min_time, int max_time);
    QString select_in_pic(QSqlDatabase *db, QString car_no, QString in_time);
    /*****张超*****begin*/
    int select_seat_count(QSqlDatabase *db);
    //杰哥
    bool updated_car_bind_time(QSqlDatabase *db,QString last_time);
    bool updated_car_stall_time(QSqlDatabase *db,QString last_time);
    bool update_updateTime_vehicle(QSqlDatabase *db,QString lasttime);
    QString select_updateTime_vehicle(QSqlDatabase *db);
    bool deleteUser(QSqlDatabase *db);//清空用户表
};

#endif // DATEBASE_H
